package com.sinosoft.emplmis.labor.service;

import java.util.List;
import java.util.UUID;
import java.util.Date;

import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;

import com.sinosoft.emplmis.labor.entity.LaborInfoEntity;
import com.sinosoft.emplmis.labor.manager.LaborInfoManager;
import com.sinosoft.emplmis.labor.web.dto.LaborInfoData;
import com.sinosoft.emplmis.labor.web.dto.LaborSearchData;
import com.sinosoft.framework.core.api.domain.UserOrgData;
import com.sinosoft.framework.core.common.exception.BusinessException;

public class LaborInfoService {
	
	/**
	 * 劳动力信息类
	 */
	private LaborInfoManager laborInfoManager;
	
	public LaborInfoManager getLaborInfoManager() {
		return laborInfoManager;
	}

	public void setLaborInfoManager(LaborInfoManager laborInfoManager) {
		this.laborInfoManager = laborInfoManager;
	}

	/**
	 * 获取劳动力信息总表
	 * @return
	 */
	 public List<LaborInfoEntity> selectAll(LaborSearchData data){
	     return laborInfoManager.selectAll(data);
	 }
	 
	 public List<LaborInfoEntity> selectLoseContact(LaborSearchData data){
		 return laborInfoManager.selectLoseContact(data);
	 }
	 
	 /**
      * 添加劳动力信息
	  * @return
	  */
	 public void saveLaborInfo(LaborInfoData record){
		 LaborInfoEntity laborInfoEntity = new LaborInfoEntity();
		 //生成唯一主键
		 record.setLaborinfoId(UUID.randomUUID().toString().trim().replaceAll("-", ""));
		 
//		 Session session = SecurityUtils.getSubject().getSession();
//		 //用户机构信息
//		 UserOrgData userOrgData = (UserOrgData) session.getAttribute("userOrg");
//		 if(userOrgData==null){
//			 throw new BusinessException("当前用户没有设定社区");
//		 }
//		 
//		 //将Street,StreetName,Community,CommunityName存入数据库中
//		 personInfoEntity.setStreet(Integer.toString(userOrgData.getpOrgId()));
//		 personInfoEntity.setStreetName(userOrgData.getpOrgName());
//		 
//		 laborInfoEntity.setStreet(record.getStreet());
//		 
//		 personInfoEntity.setCommunity(Integer.toString(userOrgData.getOrgId()));
//		 personInfoEntity.setCommunityName(userOrgData.getOrgName());
//		 laborInfoEntity.setCommunity(record.getCommunity());

		 //将dto转换为实体类
		 laborInfoEntity.toEntityData(laborInfoEntity,record,"");
		 laborInfoEntity.setInputdate(new Date());
//		 laborInfoEntity.setModifydate(new Date());
		 laborInfoManager.insert(laborInfoEntity);
	 }
	 
	 /**
	  * 根据主键获取一条劳动力信息
	  * @param 
	  * @return
	  */
	 public LaborInfoEntity selectByPrimaryKey(String laborinfoId){
		 return laborInfoManager.selectByPrimaryKey(laborinfoId);
	 }
	   
	 /**
	  * 根据主键删除一条劳动力信息
	  * @param jytjId
	  * @return
	  */
	 public int deleteByPrimaryKey(String laborinfoId) {
	     return laborInfoManager.deleteByPrimaryKey(laborinfoId);
     }
	   
	 /**
	  * 根据主键修改劳动力信息
	  * @param record
	  * @return
	  */
	 public int updateLaborInfo(LaborInfoEntity record) {
		 record.setModifydate(new Date());
		 return laborInfoManager.updateLaborInfo(record);
	 }
	 
	 /**
	  * 根据主键修改失联人员信息
	  * @param record
	  * @return
	  */
	 public int updateLoseTouch(LaborInfoEntity record) {
		 record.setModifydate(new Date());
		 return laborInfoManager.updateLoseTouch(record);
	 }
	   
	 /**
	  * 获取总条目数
	  * @param data
	  * @return
	  */
	 public int count(LaborSearchData data){
	     return laborInfoManager.count(data);
     }
	 
	 /**
	  * 获取失联总条目数
	  * @param data
	  * @return
	  */
	 public int countlose(LaborSearchData data){
	     return laborInfoManager.countlose(data);
     }
}

